home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 25 / CU Amiga Magazine's Super CD-ROM 25 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-08].iso / CUCD / Magazine / C_Tutorial / Part-13 / PatchLib / source / include / private / patch.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-20  |  14.1 KB  |  305 lines

  1. #ifndef LIBRARIES_PATCHPRIVATE_H
  2. #define LIBRARIES_PATCHPRIVATE_H
  3. /*****************************************************************************/
  4. /*
  5. **    Filename:    libraries/patchPRIVATE.h
  6. **    Release:    6.0
  7. **    Date:        19.08.97
  8. **
  9. **    definition of patch.library PRIVATE structures and returncodes
  10. **
  11. **    (C) Copyright 1993-97 Stefan Fuchs
  12. **    All Rights Reserved
  13. */
  14. /*****************************************************************************/
  15.  
  16. #ifndef    EXEC_TYPES_H
  17. #include <exec/types.h>
  18. #endif
  19.  
  20. #ifndef    EXEC_LISTS_H
  21. #include    <exec/lists.h>
  22. #endif    /* EXEC_LISTS_H */
  23.  
  24. #ifndef    EXEC_LIBRARIES_H
  25. #include    <exec/libraries.h>
  26. #endif    /* EXEC_LIBRARIES_H */
  27.  
  28. #ifndef    EXEC_SEMAPHORES_H
  29. #include    <exec/semaphores.h>
  30. #endif    /* EXEC_SEMAPHORES_H */
  31.  
  32. #ifndef    UTILITY_TAGITEM_H
  33. #include <utility/tagitem.h>
  34. #endif
  35.  
  36.  
  37. /*----------------------------------------------------------------------------*/
  38.  
  39. /* ErrorCodes */
  40. #define PATERR_Ok        0    /* Everything Ok                */
  41. #define PATERR_PatchInUse    1    /* Patch Usecount <> 0                */
  42. #define PATERR_InvalidHandle    2    /* Pointer to patch is not (no longer) valid    */
  43. #define PATERR_OutOfMem        3    /* Out of memory                */
  44. #define PATERR_OpenLib        4    /* Failed to open requested library        */
  45. #define PATERR_FuncNotStd    5    /* Function to patch is not in the standard format */
  46. #define PATERR_PatchInstalled    6    /* Can't remove patch because another program has  */
  47.                     /* installed a non-patch.library patch later       */
  48. #define PATERR_InvalidTags    7    /* There was an error in the combination of the specified Tags */
  49. #define PATERR_OpenDev        8    /* Failed to open requested device */
  50. #define PATERR_NoTaskList    9    /* PATT_AddTask... or PATT_RemTask... was specified for a patch, */
  51.                     /* which had no PATT_CreateTaskList set */
  52. #define PATERR_TaskListExists    10    /* PATT_CreateTaskList was specified, but there already exists a TaskList */
  53. #define PATERR_InvalidTaskList    11    /* PATT_CreateTaskList was specified with a wrong parameter */
  54. #define PATERR_PatchUnnamed    12    /* PATT_PatchName with GetPatch was specified, for a patch without an IDString */
  55. #define PATERR_NoSemaphore    13    /* Could not allocate semaphore */
  56.  
  57. #define PATERR_KickTooOld    14    /* Kickstart version is too old for this function */
  58. #define PATERR_InvalidPattern    15    /* Pattern passed via PATT_AddTaskPattern is not valid */
  59. #define PATERR_Restricted    16    /* Certain tags/features may not be used when patching certain functions */
  60.  
  61.  
  62. /*----------------------------------------------------------------------------*/
  63. struct PatchNotifyMessage {
  64.     struct Message pnm_ExecMessage;
  65.     ULONG  pnm_Class;
  66.     UWORD  pnm_Code;
  67.     APTR   pnm_Object;
  68. };
  69.  
  70. /*----------------------------------------------------------------------------*/
  71. #define PATCHNOTIFY_CLASS    0x50000000
  72. /*----------------------------------------------------------------------------*/
  73. /*Notification codes (pnm_Code) (ignore messages with other codes): */
  74. #define PATCOD_PatchInstalled    1    /* new patch has been added */
  75. #define PATCOD_PatchRemoved    2    /* a patch has been removed */
  76. #define PATCOD_PatchChanged    3    /* attributes of a patch have been changed */
  77.  
  78. /*----------------------------------------------------------------------------*/
  79. #define    PatchName "patch.library"
  80. #define STACKSLOTS 5    /* (V6) Maximum number of stacks, which can be preallocated for stackextension feature */
  81.  
  82. /*------------------------------------------------------------------------------*/
  83. struct MasterPatch            /* This structure is PRIVATE */
  84. {
  85. struct    Node    MPS_Node;        /* ln_Name may contain a pointer to the name of the patched library */
  86.     UWORD    MPS_Flags;        /* see below */
  87. struct    MinList    MPS_PatchHeader;    /* Listheader Structure for Patch structures */
  88. struct    Library    *MPS_PatchedLibraryBase; /* Pointer to patched Library */
  89.     WORD    MPS_PatchedLVO;        /* Library Vektor Offset in patched library */
  90.     UWORD    MPS_OldEntry01;        /* original entry point */
  91.     ULONG    MPS_OldEntry02;
  92.     APTR    MPS_PatchIORequest;    /* Pointer to IORequest for CloseDevice() (if available) */
  93.     APTR    MPS_SetFunctionResult;    /* Pointer to result of SetFunction */
  94.                     /* (only used when the UseSetFunction Bit is set) */
  95.                     /* This need not equal the contents of MPS_OLDEntry, if a SetFunction Manager is installed */
  96.  
  97. struct    PatchStack *MPS_StackSlots[STACKSLOTS+1]; /* (V6) Array of pointers of preallocated stacks */
  98.  
  99.  
  100. };
  101.  
  102. /* Master Patch Struct Flags */
  103. #define MPSB_CloseLib        0    /* Patch.library opened the library */
  104. #define MPSB_CloseDev        1    /* Patch.library opened the device */
  105. #define MPSB_IncLibUsage    2    /* Patch.library did increase library usage counter (was MPSB_PatchSV) */
  106. #define MPSB_Attached        3    /* Masterpatch is attached to library */
  107. #define MPSB_UseSetFunction    4    /* Use SetFunction for installing and removing patches */
  108.  
  109. #define MPSF_CloseLib        (1L<<0)    /* Patch.library opened the library */
  110. #define MPSF_CloseDev        (1L<<1)    /* Patch.library opened the device */
  111. #define MPSF_IncLibUsage    (1L<<2)    /* Patch.library did increase library usage counter (was MPSF_PatchSV) */
  112. #define MPSF_Attached        (1L<<3)    /* Masterpatch is attached to library */
  113. #define MPSF_UseSetFunction    (1L<<4)    /* Use SetFunction for installing and removing patches */
  114.  
  115.  
  116. /*----------------------------------------------------------------------------*/
  117. struct    Patch            /* This structure is PRIVATE */
  118. {
  119.     struct    Node    PS_Node;    /* ln_Name may contain a pointer to the name of the patch */
  120.     UWORD    PS_Flags;        /* see below */
  121.     struct    PatchCode *PS_PatchCode;/* Pointer to PatchCode (Code begins at Offset + 8) */
  122.     LONG    PS_UserPatchCodeSize;    /* Length of NewCode in bytes (if this field is >0 the memory starting at the UserPatch must be freed) */
  123.     struct    List PS_RemoveHookList;    /* Header of a double linked list containing */
  124.                     /* hooks to be called, when a patch is finally removed */
  125.     struct  MinNode PS_ProjectNode;    /* ListNode identifing the Project(if any), to which the */
  126.                     /* patch belongs */
  127.     ULONG    PS_UserData;        /* Application specific data */
  128.     ULONG    PS_StackSize;        /* (V6) Minimum Stacksize for this patch */
  129.     UBYTE    PS_PatchCodeType;    /* (V6) Type of PatchCode attached via PS_PatchCode (see below) */
  130.     UBYTE    PS_Pad;            /* reserved */
  131.  
  132.     APTR    PS_JmpNext;        /* (V6) Pointer to instruction to change, when linkage changes or NULL */
  133.     APTR    PS_JmpOrig;        /* (V6) Pointer to instruction to change, when linkage changes or NULL */
  134.     APTR    PS_Jsr;            /* (V6) Pointer to instruction to change, when linkage changes or NULL */
  135.     APTR    PS_SystemEntry;        /* (V6) Address to reenter patchcode or NULL */
  136.  
  137.     APTR    PS_TestUsage1;        /* (V6) Pointer to instruction, which is not covered by a usage counter or NULL */
  138.     APTR    PS_TestUsage2;        /* (V6) Pointer to instruction, which is not covered by a usage counter or NULL */
  139.     APTR    PS_TestUsage3;        /* (V6) Pointer to instruction, which is not covered by a usage counter or NULL */
  140.  
  141. };
  142. /* Patch Struct Flags: */
  143. #define PSB_PatchSV        0    /* Object was installed with PatchSupervisor active */
  144. #define PSB_OriginalType    2    /* (V6) Patch was installed with PATT_Original */
  145. #define PSB_InternalCall    3    /* (V6) Calling SetPatch() from internal function */
  146.                     /* (SetPatchA() will always clear this flag) */
  147. #define PSF_PatchSV        (1L<<0)    /* Object was installed with PatchSupervisor active */
  148. #define PSF_OriginalType    (1L<<2)    /* (V6) Patch was installed with PATT_Original */
  149.                     /* implemented for GetPatch and InstallPatchTags() */
  150. #define PSF_InternalCall    (1L<<3)    /* (V6) Calling SetPatch() from internal function */
  151.                     /* (SetPatchA() will always clear this flag) */
  152.  
  153.  
  154. /* PS_PatchCodeType: */
  155. #define PCODE_GENERIC      0    
  156. #define PCODE_START      6    /* For PS_TYPE_START */
  157. #define PCODE_ORIG      7    /* For PS_TYPE_ORIG  */
  158. #define PCODE_END      8    /* For PS_TYPE_END   */
  159.  
  160. #define PCODE_USER0     10    /* For PS_TYPE_USER   ->Replace + No UseXResult */
  161. #define PCODE_USER1     11    /* For PS_TYPE_USER   ->Replace + UseXResult    */
  162. #define PCODE_USER2     12    /* For PS_TYPE_USER   ->Pri <> 0 + NoOrig + No UseXResult */
  163. #define PCODE_USER3     13    /* For PS_TYPE_USER   ->Pri <> 0 + NoOrig + UseXResult    */
  164. #define PCODE_USER4     14    /* For PS_TYPE_USER   ->Pri >  0 + Orig   + No UseXResult */
  165. #define PCODE_USER5     15    /* For PS_TYPE_USER   ->Pri >  0 + Orig   + UseXResult */
  166.  
  167. #define PCODE_SYSTEM     14    /* same as PCODE_USER4 */
  168.  
  169. /*----------------------------------------------------------------------------*/
  170.  
  171. struct PatchProject        /* This structure is PRIVATE */
  172. {
  173. struct    Node    PPR_Node;
  174.     UWORD    PPR_Flags;    /* see below */
  175.     struct    List PPR_PatchListHeader; /* Header of a double linked list containing */
  176.                       /* patches belonging to the Project */
  177.     ULONG    PPR_UserData;          /* (V6) Application specific data (not implemented) */
  178. };
  179. /* ln_Type: PS_TYPE_PROJECT */
  180. /* ln_Name: Name of Project */
  181.  
  182. #define PPRB_InternalCall    0    /* (V6) Calling SetPatchProject() from internal function */
  183.                     /* (SetPatchProject() will always clear this flag) */
  184.                     /* (set PSF_InternalCall for all SetPatchA calls) */
  185. #define PPRF_InternalCall    (1L<<0)    /* (V6) Calling SetPatchProject() from internal function */
  186.                     /* (SetPatchProject() will always clear this flag) */
  187.                     /* (set PSF_InternalCall for all SetPatchA calls) */
  188.  
  189.  
  190. /*----------------------------------------------------------------------------*/
  191. struct TLHeader            /* This structure is PRIVATE */
  192. {
  193.     struct    List    TL_List;
  194.     ULONG    TL_Result1;    /* Result1: 0 if Type: TL_TYPE_INCLUDE otherwise 1 */
  195.     ULONG    TL_Result2;    /* Result1: 1 if Type: TL_TYPE_INCLUDE otherwise 0 */
  196. };
  197. /*----------------------------------------------------------------------------*/
  198. struct TLNode            /* This structure is PRIVATE */
  199. {
  200.     struct    Node    TN_Node;
  201.     APTR    TN_Pattern;    /* TLI_TYPE_TASKPATTERN only:Pattern returned by ParsePattern() */
  202. };
  203. /*----------------------------------------------------------------------------*/
  204. struct PatchXResult {        /* Use PatchAlloc(PS_TYPE_XRESULT) to allocate this */
  205.     struct Node pxr_Node;    /* Reserved */
  206.     ULONG  pxr_RegPattern;    /* Which of the following register fields are used */
  207.     ULONG  pxr_RegD0;
  208.     ULONG  pxr_RegD1;
  209.     ULONG  pxr_RegD2;
  210.     ULONG  pxr_RegD3;
  211.     ULONG  pxr_RegD4;
  212.     ULONG  pxr_RegD5;
  213.     ULONG  pxr_RegD6;
  214.     ULONG  pxr_RegD7;
  215.     ULONG  pxr_RegA0;
  216.     ULONG  pxr_RegA1;
  217.     ULONG  pxr_RegA2;
  218.     ULONG  pxr_RegA3;
  219.     ULONG  pxr_RegA4;
  220.     ULONG  pxr_RegA5;
  221.     ULONG  pxr_RegA6;
  222.     UWORD  pxr_FlowControl;    /* What patches follow this one (see below) */
  223. };
  224. /*----------------------------------------------------------------------------*/
  225. /* types for patch, masterpatch and project structures: */
  226. #define PS_TYPE_UNKNOWN     0    /* do not use */
  227. #define PS_TYPE_MASTER        1    /* node is MasterPatch structure */
  228. #define PS_TYPE_USER        2    /* node was installed by an Application using the library interface */
  229. #define PS_TYPE_SYSTEM        3    /* node was installed by the support program PatchSetFunc */
  230. #define PS_TYPE_DELUSER        4    /* this struct is PS_TYPE_USER, but should be removed */
  231. #define PS_TYPE_DELSYSTEM    5    /* this struct is PS_TYPE_SYSTEM, but should be removed */
  232. #define PS_TYPE_START        6    /* this struct points to a JMP */
  233. #define PS_TYPE_ORIG        7    /* this struct points to a routine that calls the old routine */
  234. #define PS_TYPE_END        8    /* this struct points to a RTS */
  235. #define PS_TYPE_PROJECT        20    /* this struct, is a Header structure to a list of PS_TYPE_USER structures belonging to one project */
  236. #define PS_TYPE_XRESULT        30    /* this struct is an PatchXResult structure */
  237.  
  238.  
  239. #define TLI_TYPE_TASKNAME    3    /* LN_NAME points to TaskName */
  240. #define TLI_TYPE_TASKID        4    /* LN_NAME points to Task structure */
  241. #define TLI_TYPE_TASKPATTERN    5       /* LN_NAME points to Token string for MatchPattern() (V5) */
  242.  
  243. /*----------------------------------------------------------------------------*/
  244. /* pre patchcode structure: */
  245. struct PatchCode {
  246.     ULONG PC_PatchXResult;        /* TRUE, if PatchXResult system is used */
  247.     struct Patch *PC_PatchStruct;    /* Pointer to PatchStruct */
  248.     ULONG PC_StackSize;        /* Stacksize required to execute the patchcode */
  249.     ULONG PC_Disable;        /* Disable nesting counter 0= Enabled */
  250.     struct TLHeader *PC_TaskList;    /* Exclude/Include List */
  251.     ULONG PC_Usage;            /* Usage Counter */
  252.     UBYTE PC_PatchCodeStart;    /* Assembler PatchCode follows */
  253. /* PatchCode: */
  254. };
  255. /*----------------------------------------------------------------------------*/
  256. /* This structure is at the high adresses (the bottom) of an extended stack */
  257. /* .... stack .... */
  258. struct PatchStack
  259. {
  260.     ULONG PST_Reserved2;        /* $CCDDEEFF */
  261.     ULONG PST_Reserved1;        /* $8899AABB */
  262. struct StackSwapStruct PST_StackSwap;    /* structure for StackSwap */
  263.     ULONG PST_Usage;        /* 1: this stack is in use  0: stack is free */
  264.     APTR  PST_OldStack;        /* Pointer to oldstack */
  265.     ULONG PST_Stacksize;        /* Size of this stack */
  266.     APTR  PST_Magic2;        /* pointer to PST_Magic1 */
  267.     ULONG PST_Magic1;        /* magic PatchStackID 'PATC' */
  268. };
  269. /*----------------------------------------------------------------------------*/
  270.  
  271.  
  272. /* Beginning of GetPatch tags (currently PRIVATE) */
  273. #define    PATT_NewCode    TAG_USER+0x5000+50    /* G: BOOL Return pointer to installed patch */
  274.                         /*     default: FALSE */
  275.  
  276. /* Beginning of PRIVATE tags */
  277. #define    PATT_SYSTEM    TAG_USER+0x5000+60    /* I: True: Install patch in system mode */
  278.                         /*     FOR PatchSetFunc *ONLY* */
  279.                          /* F: APTR Return pointer to patch structure */
  280.                         /*    of the given code pointer */
  281.                         /* G: True: return Setfunction() result */
  282. #define PATT_LVO    TAG_USER+0x5000+61    /* F: UWORD Return pointer to master patch structure */
  283.                         /*     of the given LibraryBase and LVO */
  284.                         /*     if you specify this tag you must also specify */
  285.                         /*     the public tag PATT_LibraryBase or PATT_LibraryName */
  286. #define PATT_Detach    TAG_USER+0x5000+62    /* S: BOOL the library for this patch has been closed */
  287.                         /*     Parameter (MasterPatch structure instead of Patch struct) */
  288.                            /*    FOR PatchSupervisor *ONLY* */
  289. #define PATT_Attach    TAG_USER+0x5000+63    /* S: struct Library * */
  290.                         /*     Reattach a MasterStruct to a Library */
  291.                         /*     Parameter (MasterPatch structure instead of Patch struct) */
  292.                         /*       FOR PatchSupervisor *ONLY* */
  293. /*    PATT_LibraryBase    */        /* F: APTR Return pointer to master patch structure */
  294.                         /*     of the given LibraryBase and LVO */
  295.                         /*     if you specify this tag you must also specify */
  296.                         /*     the private tag PATT_LVO */
  297. /*    PATT_LibraryName    */        /* F: APTR Return pointer to master patch structure */
  298.                         /*     of the given Libraryname and LVO */
  299.                         /*     if you specify this tag you must also specify */
  300.                         /*     the private tag PATT_LVO */
  301.  
  302.  
  303.  
  304. #endif    /* LIBRARIES_PATCHPRIVATE_H */
  305.